// JavaScript Document

//防抖
function debounce(func, wait, immediate) {
  var timeout;
  return function () {
    var context = this,
      args = arguments;
    var later = function () {
      timeout = null;
      if (!immediate) func.apply(context, args);
    };
    var callNow = immediate && !timeout;
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
    if (callNow) func.apply(context, args);
  };
}


function checkWidth() {
  if ($(window).width() > 768) {
    $('.course-list').css('display', 'block');
    $('.opocl-nav').css('display', 'none');
    $('.test').height(0);
    $('.card-list').addClass('j-justify-content-left');
    $('.card-list').removeClass('j-justify-content-around');

  } else {
    $('.opocl-nav').css('display', 'block');
    var testheight = $('.banner-img').height();
    $('.test').height(testheight - 30);
    $('.card-list').removeClass('j-justify-content-left');
    $('.card-list').addClass('j-justify-content-around');
  }
}


var nav_flag = true;

//响应式设置
$(document).ready(function () {
  $('.app-open-course-list').click(function () {
    $('.course-list').css('display', 'block')
  })
  $('.app-close-list').click(function () {
    $('.course-list').css('display', 'none')
  })
  $(window).resize(debounce(function () {
    checkWidth();
  }, 250))


  checkWidth();
  $('.app-open-nav').click(debounce(function () {
    if (nav_flag) {
      $('.opocl-nav').removeClass('fa-list').addClass('fa-list-ul');
      $('.app-nav').animate({
        left: 0
      });
      nav_flag = false;
    } else {
      $('.opocl-nav').addClass('fa-list').removeClass('fa-list-ul');
      $('.app-nav').animate({
        left: '-200px'
      });
      nav_flag = true;
    }
  }, 250))
})

function craeteCourseImg(){
	let name_arr=new Array();
	for(let i=0;i<4;i++){
		name_arr[i]='file'+(i+1);
	}
	return name_arr;
}

function ElementEventFun(EventType,trgetEl, callback) {
	if($(trgetEl).length<0){
		console.log('error:没有匹配的元素!');
		return;
	}
	$(document).on(EventType,trgetEl, callback);  
}
